<template>
    <div class="searchPatient">
        <navBar :titleName="titleName"></navBar>
        <search @messageData="getData" style="margin-top: 42px;" placeText="输入诊断名称"
                textInfo="查询"></search>
        <div class="patientlist">
            <div class="patient" v-for="(item,index) in patientList" :key="index">
                <mycell
                        :title="item.name"
                        desc=""
                        :showIcon="true"
                        :isLink="true"
                        @myClickHandler="chooseItem(item)">
                </mycell>
            </div>
        </div>
    </div>
</template>

<script>
    /* eslint-disable no-console,no-unused-vars */

    import navBar from '@/components/common/navBar.vue'
    import search from '@/components/common/search.vue'
    import mycell from '@/components/common/my-cell.vue'

    export default {
        name: "searchPatient",
        components: {
            mycell,
            search,
            navBar
        },
        data() {
            return {
                titleName: "诊断查询",
                kind: "",
                search: "",
                patientList: []
            }
        },
        created() {
            let item = this.$route.params.item;
            if (item) {
                this.kind = item;
            }
            this.getData();
        },
        methods: {
            getData(val) {
                if (this.search === "") {
                    this.search = val;
                } else {
                    if (this.search === val) {
                        return;
                    }
                }
                console.log("------获取诊断列表------");
                this.API.POST(this.ApiUrl.POST_GET_DIAGNOSIS, {
                    search: val
                }).then(({data}) => {
                    console.log("诊断列表------", data);
                    if (data.code === 1200) {
                        this.patientList = data.data;
                    }
                }).catch(err => {
                    console.log("getDiagnosis::err------", err);
                });
            },
            chooseItem(item) {
                console.log("------item-----");
                console.log(item);
                if (this.kind === "diagMain") {
                    this.$store.state.diagMain = item.name;
                } else {
                    this.$store.state.diagSecond = item.name;
                }
                this.$router.back();
                console.log("------item-----");
            }
        }
    }

</script>

<style scoped>
    .patient {
        min-height: 40px;
        border-bottom: 1px solid #ccc;
        background-color: white;
    }

    .patientlist {
        background-color: #e6e6e6;
    }

</style>